const getBase64 = function (img) { //传入图片路径，返回base64，使用getBase64(url).then(function(base64){},function(err){}); 
    let getBase64Image = function (img, width, height) { //width、height调用时传入具体像素值，控制大小,不传则默认图像大小
        let canvas = document.createElement("canvas");
        canvas.width = width ? width : img.width;
        canvas.height = height ? height : img.height;
        let ctx = canvas.getContext("2d");
        ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
        let dataURL = canvas.toDataURL();
        return dataURL;
    }
    let image = new Image();
    image.crossOrigin = '';
    image.src = img;
    let deferred = $.Deferred();
    if (img) {
        image.onload = function () {
            deferred.resolve(getBase64Image(image));
        }
        return deferred.promise();
    }
}